package com.ricky.onlineShop.controller.trading;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ricky.onlineShop.serviceBus.trading.TradingServiceBus;
import com.ricky.onlineShop.shop.trading.pojo.Trading;
import com.ricky.onlineShop.shop.trading.vo.TradingVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ricky.common.annotation.Log;
import com.ricky.common.core.controller.BaseController;
import com.ricky.common.core.domain.AjaxResult;
import com.ricky.common.enums.BusinessType;
import com.ricky.common.utils.poi.ExcelUtil;
import com.ricky.common.core.page.TableDataInfo;

/**
 * @Author staticlan
 * @Date 2024/6/20 15:41
 * @Description:
 */
@RestController
@Api(tags = {"在线交易"})
@Slf4j
@RequestMapping("/onlineShop/trading")
public class TradingController extends BaseController
{
    @Autowired
    private TradingServiceBus tradingServiceBus;

    /**
     * 新增trading
     */
    //@PreAuthorize("@ss.hasPermi('onlineShop:trading:add')")
    @Log(title = "trading", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TradingVo trading) {
        return AjaxResult.success(tradingServiceBus.saveInfo(trading));
    }

    /**
     * 拍下网店
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:auction')")
    @GetMapping(value = "/tradingAuction/{id}")
    public AjaxResult tradingAuction(@PathVariable("id") String id)
    {
        return toAjax(tradingServiceBus.tradingAuction(id));
    }

    /**
     * 查询trading列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:list')")
    @GetMapping("/list")
    public TableDataInfo list(Trading trading)
    {
        startPage();
        List<Trading> list = tradingServiceBus.selectTradingList(trading);
        return getDataTable(list);
    }
    /**
     * 查询trading列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:list')")
    @GetMapping("/myList")
    public TableDataInfo myList(Trading trading)
    {
        startPage();
        List<Trading> list = tradingServiceBus.selectMyTradingList(trading);
        return getDataTable(list);
    }

    /**
     * 导出trading列表
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:export')")
    @Log(title = "trading", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Trading trading)
    {
        List<Trading> list = tradingServiceBus.selectTradingList(trading);
        ExcelUtil<Trading> util = new ExcelUtil<Trading>(Trading.class);
        util.exportExcel(response, list, "trading数据");
    }

    /**
     * 获取trading详细信息
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tradingServiceBus.selectTradingById(id));
    }

    /**
     * 修改trading
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:edit')")
    @Log(title = "trading", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TradingVo trading)
    {
        return AjaxResult.success(tradingServiceBus.updateTrading(trading));
    }

    /**
     * 删除trading
     */
    @PreAuthorize("@ss.hasPermi('onlineShop:trading:remove')")
    @Log(title = "trading", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tradingServiceBus.deleteTradingByIds(ids));
    }


    @GetMapping(value = "/myTradings")
    public AjaxResult myTradings() {
        return AjaxResult.success(tradingServiceBus.myTradings());
    }
}

